//
//  BaseTableViewController.swift
//  RacWeibo
//
//  Created by hanxu on 15/10/8.
//  Copyright © 2015年 hanxu. All rights reserved.
//

import UIKit
import ReactiveCocoa

class BaseTableViewController: UITableViewController {

    var userLogin = false
    var visitorView : VisitorView?
    
    override func loadView() {
        userLogin ? super.loadView() : setupVistorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    private func setupUI() {
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "register")
    }
    
    func setupVistorView() {
        
        visitorView = VisitorView()
        
        view = VisitorView()

        visitorView?.loginButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.registerButton.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    @objc func login() {
        
        let nav = UINavigationController(rootViewController: OAuthController())
        presentViewController(nav, animated: true, completion: nil)
    }
    
    @objc func register() {
        
        printLog("注册")
    }

 
}
